<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" href="../../css/api.css" />
    <link rel="stylesheet" href="../../css/common.css" />
</head>

<body>
    <header class="yt-header">
        <h1 class="yt-header-title">文件</h1>
    </header>
    <section class="content">
        <button class="button block" onclick="openFile()">预览文件</button>
        <div class="resault">

        </div>
    </section>
</body>
<script src="../../script/api.js"></script>
<script>
    /*
    *  模块 superFile 文档 https://docs.apicloud.com/Client-API/Open-SDK/superFile
    *  api.download 文档 https://docs.apicloud.com/Client-API/api#17
    */
    var superFile = null

    // 是否在真是设备上运行
    var deviceReady = false
    // 文件类型 word excel pdf txt 等文件
    var filePath = 'http://118.26.73.70:23360/xwaj/files/xwajAppId/442a45e4d023a979dc3c2bcaf3da57b8_%E6%B5%8B%E8%AF%95.doc'

    apiready = function() {
      deviceReady = true
    }

    function openFile() {

      if (!deviceReady) {
        alert('apiready is false')
        return
      }
        // TODO word,pdf,excel,txt 等文件，需要先下载本地，然后在预览。那看完了怎么删除呢？岂不是垃圾越来越多？
        superFile = api.require("superFile")
        api.download({
            url: filePath,
        },function(ret, err){
            if(ret.state == 1){
              alert(ret.savePath)
              superFile.open({
                  path: ret.savePath
              })
            }else{
              alert('文件下载失败')
            }
        })
    }
</script>

</html>
